capture log close
log using "B:\Col_Minimum_Wage\Code\Clean/clean_rr_ValorAgregado.txt", replace text
/*==================================================
project:       Limpiar y unir bases de VA total por departamento para 1990-2005
Author:        Diego Mayorga Córdova 
E-email:       
url:           
Dependencies:  Banco de México
----------------------------------------------------
Creation Date:     4 Feb 2020 - 11:31:49
Modification Date:   
Do-file version:    01
References:          
Output:             
==================================================*/

/*==================================================
              0: Program set up
==================================================*/
version 15.1
drop _all

glo carpeta 	"B:\Col_Minimum_Wage"
glo codigo 		"$carpeta/Code"
glo data		"$carpeta/Data"
glo ster 		"$carpeta/Ster"

/*==================================================
              1: 
==================================================*/
forvalues yyyy =1990/2005{
	use "$data/Importable/PIBdept/VAdept_`yyyy'.dta" , clear
	gen año = `yyyy'
	loc k = 0
	foreach var of varlist B-AT{
		if `yyyy' == 1990 {
			replace `var' = subinstr(`var'," ", "",.)
			replace `var' = subinstr(`var',"-", "",.)
			loc name_`var' = `var'[6]
			loc name_`var' = "`name_`var''"+`var'[7]
			loc name_`var' = "`name_`var''"+`var'[8]
			loc name_`var' = "`name_`var''"+`var'[9]
			loc name_`var' = "`name_`var''"+`var'[10]
			loc name_`var' = "`name_`var''"+`var'[11]
			loc name_`var' = substr("`name_`var''",1,32)
			if "`name_`var''"=="ASOCIACIONESESPARCIMIENTOYOTROSS"{
				if `k' == 0{
					loc name_`var' ="ASOCIACIONESESPARCIMIENTOYOTROSM"
				}
				else{
					loc name_`var' ="ASOCIACIONESESPARCIMIENTOYOTRONM"
				}
				loc ++k
			}
		}
		destring `var', replace force
	}
	drop in 1/13
	drop in 25/27
	drop in 34
	drop in 35/570
	tempfile yy`yyyy'
	save `yy`yyyy''
}
/*==================================================
              2: 
==================================================*/
use `yy1990'
forvalues yyyy = 1991/2005{
	append using `yy`yyyy''
}

foreach var of varlist B-AT{
	rename `var' `name_`var''
}
rename A departamento
order departamento año , first
/*==================================================
              3: 
==================================================*/
keep departamento año INTERMEDIACIONFINANCIERAYSERVICI INMOBILIARIOSYALQUILERDEVIVIENDA EMPRESASEXCEPTOSERVICIOSFINANCIE
rename INTERMEDIACIONFINANCIERAYSERVICI va_intermed_fin
rename INMOBILIARIOSYALQUILERDEVIVIENDA va_vivienda
rename EMPRESASEXCEPTOSERVICIOSFINANCIE va_empresas_noservfin

/*==================================================
              4: 
==================================================*/

	
gen area = .
	replace area = 8  if departamento == "Atlántico"
	replace area = 11 if departamento == "Cundinamarca"
	replace area = 68 if departamento == "Santander"
	replace area = 76 if departamento == "Valle"
	replace area = 17 if departamento == "Caldas"
	replace area = 5  if departamento == "Antioquia" | departamento == "Antioquía"
	replace area = 52 if departamento == "Nariño"
drop if area == .
rename año year

tsset year area

foreach var in va_intermed_fin va_vivienda va_empresas_noservfin{
	gen rez_`var' = `var'[_n-1]
}
/*==================================================
              5: 
==================================================*/
save "$data/Clean/PIBdept/VAdept.dta", replace





log close
exit
/* End of do-file */

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Notes:
1.
2.
3.


Version Control:


